from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re


from selenium.webdriver.common.keys import Keys
#from selenium.webdriver.remote import Command

PROXY_HOST = "127.0.0.1"
PROXY_PORT = 8118

fp = webdriver.FirefoxProfile()

# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
fp.set_preference("network.proxy.type", 1)

fp.set_preference("network.proxy.http", PROXY_HOST)
fp.set_preference("network.proxy.http_port", PROXY_PORT)
fp.set_preference("network.proxy.ftp", PROXY_HOST)
fp.set_preference("network.proxy.ftp_port", PROXY_PORT)
fp.set_preference("network.proxy.ssl", PROXY_HOST)
fp.set_preference("network.proxy.ssl_port", PROXY_PORT)

fp.set_preference("network.proxy.no_proxies_on", "") # set this value as desired

#driver = webdriver.Firefox(firefox_profile=fp)



driver = webdriver.Firefox(firefox_profile=fp) # Get local session of firefox

#driver = webdriver.Firefox()
driver.implicitly_wait(10)
base_url = "http://twitter.com/"

driver.get(base_url)
driver.find_element_by_xpath("//div[@id='front-container']/div[2]/div/form/fieldset/div/input").clear()
driver.find_element_by_xpath("//div[@id='front-container']/div[2]/div/form/fieldset/div/input").send_keys("serinskiivan")
driver.find_element_by_xpath("//div[@id='front-container']/div[2]/div/form/fieldset/div[2]/input").clear()
driver.find_element_by_xpath("//div[@id='front-container']/div[2]/div/form/fieldset/div[2]/input").send_keys("1q2w3e4r"+Keys.RETURN)
time.sleep(25)
driver.find_element_by_css_selector("#new-tweet > span").click()
time.sleep(2)
driver.find_element_by_css_selector("div.twttr-dialog-content > div.tweet-box > div.text-area > div.text-area-editor.twttr-editor > textarea.twitter-anywhere-tweet-box-editor").clear()
driver.find_element_by_css_selector("div.twttr-dialog-content > div.tweet-box > div.text-area > div.text-area-editor.twttr-editor > textarea.twitter-anywhere-tweet-box-editor").send_keys(" demo post pishu robotika")
driver.find_element_by_xpath("//div[@id='tweet_dialog']/div/div[2]/div[2]/div/div/div[3]/div[2]/a").click()
time.sleep(15)
#print driver
driver.close()

driver = webdriver.Firefox() # Get local session of firefox

#driver = webdriver.Firefox()
driver.implicitly_wait(10)

driver.get("http://pda.mblogi.qip.ru/")
driver.find_element_by_id("login").click()
driver.find_element_by_id("login").send_keys("seanna8z")
driver.find_element_by_id("passw").click()
driver.find_element_by_id("passw").clear()
driver.find_element_by_id("passw").send_keys("tswk4vleq")
driver.find_element_by_css_selector("input.button_med").click()
driver.find_element_by_id("text").clear()
driver.find_element_by_id("text").send_keys('vona 13222 vo vo vo vo')
driver.find_element_by_id("post_msg_submit").click()
